Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

287
Views
"unexpected end of input" when Jinja templating used to provide multiple parameters to onclick function

I'm trying to run a js function using parameters passed into the template via jinja, where item contains strings as follows:

item.id = 'item1'
item.indicator = 'yes' #or no

Template code:

{% for item in items %}
        <!--The error is thrown by the line directly below!-->
        <div class='qitem' id='{{item.id}}' onclick = change_background('{{item.indicator}}', '{{item.id}}')></div>
{% endfor %}

<script>
function change_background(indicator, id){
    if (indicator == 'yes'){
        document.getElementById(id).style.background='lightgreen';
    }else{
        document.getElementById(id).style.background='pink';
</script>

In the culpable line in my code, '{{item.indicator}}' is red, and the first ' is underlined in vscode.

The code works despite this, if only ONE argument it used as follows: change_background('{{item.indicator}}') (with corresponding function adjusted accordingly), but does not work if I try to use two arguments.

The order of the arguments doesn't seem to matter. Neither does using "{{}}" instead of '{{}}'.

Additionally, if I attempt to run two functions onclick: <div class='qitem' id='{{item.id}}' onclick = make_green('{{item.id}}'); increment_click('{{item.indicator}}')>

only the first executes, and the second is ignored without any errors being thrown!

I've searched on here and elsewhere. I don't really want to jsonify the data I pass in to the template. I feel as though there's a nuance I'm missing when using jinja.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The nuance here is simply your use of JavaScript in HTML.

You'll need

onclick="change_background('{{item.indicator}}', '{{item.id}}')"

instead of

onclick = change_background('{{item.indicator}}', '{{item.id}}')>

to properly wrap the JavaScript segment in quotes.

Additionally, if I attempt to run two functions onclick:

<div class='qitem' id='{{item.id}}' onclick = > make_green('{{item.id}}'); increment_click('{{item.indicator}}')>

Same thing here.

onclick="make_green('{{item.id}}');increment_click('{{item.indicator}}')"
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!